﻿@{
    ViewBag.Title = "Product Listing";
    var pagedList = (IPagedList)ViewBag.Names;
}

@using X.PagedList.Mvc.Core; @*import this so we get our HTML Helper*@
@using X.PagedList;
@*import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)*@
@using X.PagedList.Mvc.Core.Fluent


<!-- import the included stylesheet for some (very basic) default styling -->
<link href="/css/PagedList.css" rel="stylesheet" type="text/css" />

<!-- loop through each of your products and display it however you want. we're just printing the name here -->
<h2>List of Products</h2>
<ul>
    @foreach (var name in ViewBag.Names)
    {
        <li>@name</li>
    }
</ul>

<!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
@Html.PagedListPager(pagedList, page => Url.Action("Index", new { page }))

<h3>Fluent pager</h3>
@(Html.Pager(pagedList)
    .Url(page => Url.Action("Index", new { page }))
    .Build())

<h3>Pager for #85</h3>
@(Html.Pager(pagedList)
    .Url(page => Url.Action("Index", new { page }))
    .WithPartialView("Paging/_Pager_85")
    .DisplayLinkToFirstPage (PagedListDisplayMode.IfNeeded)
    .DisplayLinkToLastPage(PagedListDisplayMode.IfNeeded)
    .DisplayLinkToPreviousPage()
    .DisplayLinkToNextPage()
    .MaximumPageNumbersToDisplay(3)
    .Build())

<h3>Pager with ItemSliceAndTotalPosition at the end</h3>
@Html.PagedListPager(pagedList,
    page => Url.Action("Index",
        new { page }),
        new PagedListRenderOptions()
        {
            DisplayItemSliceAndTotal = true,
            ItemSliceAndTotalPosition = ItemSliceAndTotalPosition.End
        })

<h3>Pager with ItemSliceAndTotalPosition at the beginning</h3>
@Html.PagedListPager(pagedList,
    page => Url.Action("Index",
        new { page }),
    new PagedListRenderOptions()
    {
        DisplayItemSliceAndTotal = true,
    })